/*
 * Licensed to the 南京汇海交通科技有限公司
 *
 * Copyright (c) 2025.
 * All rights reserved.
 *
 * 本软件属南京汇海交通科技有限公司所有，在未获得南京汇海交通科技有限公司正式授权情况下，任何企业和个人，不能获取、阅读、安装、传播本软件涉及的任何受知识产权保护的内容。
 */
package com.cje.basic.base;

import com.chframework.boot.cache.core.CommonCacheHandler;
import com.chframework.common.context.BeanLifecycle;
import com.cje.basic.dao.DictDataDAO;
import com.cje.basic.dao.DictTypeDAO;
import com.cje.basic.properties.BasicBizProperty;
import com.cje.client.service.LocationServiceClient;
import com.cje.client.support.DefaultFeignInterceptor;
import com.cje.client.support.FeignClientProxyBuilder;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.concurrent.ExecutorService;

/**
 * 所有业务逻辑类的基类，
 * 为了消除引用DAO对象的重复编码，此处统一管理所有业务逻辑类对DAO引用
 */
public abstract class BaseService extends BeanLifecycle implements InitializingBean, DisposableBean {

    //region initMethod & destroyMethod - simple
    @Override
    protected void initMethod() {
        //something will be done at start up.
    }

    @Override
    protected void destroyMethod() {
        //something will be done at tear down.
    }
    //endregion

    //region InitializingBean & DisposableBean - simple
    @Override
    public void afterPropertiesSet() throws Exception {
        //something will be done at start up.
        locationService = feignClientProxyBuilder.proxy(basicBizProperty.getPandaUrl(),
                LocationServiceClient.class, new DefaultFeignInterceptor());
    }

    @Override
    public void destroy() throws Exception {
        //something will be done at tear down.
    }
    //endregion

    protected CommonCacheHandler cacheHandler;
    protected ExecutorService asyncExecutor;
    protected BasicBizProperty basicBizProperty;
    protected FeignClientProxyBuilder feignClientProxyBuilder;

    @Autowired
    public void setCacheHandler(CommonCacheHandler cacheHandler) {
        this.cacheHandler = cacheHandler;
    }

    @Autowired
    public void setAsyncExecutor(ExecutorService asyncExecutor) {
        this.asyncExecutor = asyncExecutor;
    }

    @Autowired
    public void setBasicBizProperty(BasicBizProperty basicBizProperty) {
        this.basicBizProperty = basicBizProperty;
    }

    @Autowired
    public void setFeignClientProxyBuilder(FeignClientProxyBuilder feignClientProxyBuilder) {
        this.feignClientProxyBuilder = feignClientProxyBuilder;
    }

    protected LocationServiceClient locationService;
    protected DictTypeDAO dictTypeDAO;
    protected DictDataDAO dictDataDAO;

    @Autowired
    public void setDictTypeDAO(DictTypeDAO dictTypeDAO) {
        this.dictTypeDAO = dictTypeDAO;
    }

    @Autowired
    public void setDictDataDAO(DictDataDAO dictDataDAO) {
        this.dictDataDAO = dictDataDAO;
    }

}
